<template>
    <div class="photoinfo-container">
        <h3>{{info.title}}</h3>
        <p class="subtitle">
            <span>发表时间：{{info.add_time | dateFormat}}</span>
            <span>点击：{{info.click}}次</span>
        </p>
        <hr>
        <!-- 缩略图区域 -->
        <div class="thumbs">
            <img class="preview-img" v-for="(item,index) in list" :src="item.src" height="100" @click="$previe.open(index,list)" alt="" :key="item.src">
        </div>
        <!-- 内容区域 -->
        <div class="content" v-html="info.content"></div>
        <cmt-box :id="id"></cmt-box>
    </div>
</template>
<script>
    import comment from '../subcomponents/comment.vue'
    export default{
        data(){
            return {
                id:this.$route.params.id,//要查看图片的ID
                inof:{},//图片详情
                list:[]//缩略图数据
            }
        },
        created(){
            this.getPhotoInfo();
            this.getThumbs();
        },
        methods:{
            getPhotoInfo(){
                //获取图片详情
                this.$http.get('api/getimageInfo/'+this.id).then(result => {
                    if(result.body.status === 0){
                        this.info = result.body.message[0];
                    }
                })
            },
            getThumbs(){
                //获取缩略图
                this.$http.get('api/getthumimages/'+id).then(result => {
                    if(result.body.status ===0){
                        //循环得到的缩略图数组的每一项，把 每张图片的信息补充完整
                        result.body.message.forEach(item => {
                            item.w = 600;
                            item.h = 400;
                        });
                        //把数据保存到 data中
                        this.list = result.body.message[0];
                    }
                })
            }
        },
        components:{
            'cmt-box':comment
        }
    }
</script>

<style lang="scss" scoped>
    .photoinfo-container{
        padding:4px;
        h3{
            font-size: 18px;
            color:#226aff;
            margin:15px 0;
        }
        .subtitle{
            display:flex;
            justify-content: space-between;
        }
        .content{
            font-size: 14px;
            line-height: 30px;
        }
        .thumbs{
            img{
                margin:10px;
                box-shadow: 0 0 8px #999;
            }
        }
    }
</style>
